package com.study.leetcode;

import java.util.Arrays;

/**
 * 移动零，将数组中所有的零移动到末尾
 */
public class moveZero {

    public static void main(String[] args) {
        int[] arr ={0,0,1,1,1};
        moveZeroes(arr);
    }
    public static void moveZeroes(int[] nums) {

        //遍历总长度
        int n = nums.length;
        int pushNum = 0;

        int changeIndex = n-1;

        for (int i = 0; i <nums.length; i++) {

            //元素为0
            if(nums[pushNum] == 0) {

                //移除
                for (int j = pushNum; j < n; j++) {

                    //边界
                    if (j != n - 1) {
                        //前挪
                        nums[j] = nums[j + 1];
                    }
                }
                nums[changeIndex] = 0;
                changeIndex--;
                //需要遍历的数组长度减1
                n--;
            }else {
                //不等于0，
                pushNum++;
            }
        }
        //System.out.println(Arrays.toString(nums));
    }

}
